{{template "admin/header.html"}}
<title>更新页面模板 - GPRESS</title>
<script type="text/javascript" src="{{basePath}}admin/js/sha3.min.js"></script>
{{template "admin/bodystart.html"}}
        <div class="layui-card layui-panel" style="height: 100%;">
          <div class="layui-card-header">
            更新页面模板
          </div>
          <div class="layui-card-body">
            <form class="layui-form" id="gpress-form" action="{{basePath}}admin/{{.UrlPathParam}}/update" method="POST">
				<div class="layui-form-item layui-col-md6">
				  <label class="layui-form-label">ID</label>
				  <div class="layui-input-block">
					<input type="hidden" name="id" id="id" value="{{.Data.Id}}" />
				    <input type="hidden" name="status" id="status" value=1 />
					<input type="text" class="layui-input" disabled value="{{.Data.Id}}" />
				  </div>
				</div>
				<div class="layui-form-item layui-col-md6">
					<label class="layui-form-label">模板名称</label>
					<div class="layui-input-block">
					  <input type="text" name="name" lay-verify="required" lay-reqtext="请填写模板名称" autocomplete="off" class="layui-input" value="{{.Data.Name}}">
					</div>
				</div>
	  
				<div class="layui-form-item layui-col-md6">
				  <label class="layui-form-label">模板路径</label>
				  <div class="layui-input-block">
					<input type="text" name="templatePath" lay-verify="required" lay-reqtext="请填写模板路径" autocomplete="off" class="layui-input" value="{{.Data.TemplatePath}}">
				  </div>
				</div>
				<div class="layui-form-item layui-col-md6">
					<label class="layui-form-label">排序</label>
					<div class="layui-input-block">
					  <input type="number" name="sortNo" lay-verify="required" lay-reqtext="请填写排序" autocomplete="off" class="layui-input" value="{{.Data.SortNo}}">
					</div>
				</div>				
				<div class="layui-form-item">
					<div class="layui-input-block">
					  <button type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="gpress-form-ajax-update">提交修改</button>
					</div>
				</div>
			</form>
          </div>
        </div>
{{template "admin/bodyend.html"}}

<script>
	layui.use(function(){
	  var form = layui.form;
	  var layer = layui.layer;
	  var $ =layui.jquery;
	  // 提交事件
	  form.on('submit(gpress-form-ajax-update)', function(data){
		var field = data.field; // 获取表单字段值
		field.sortNo=field.sortNo-0;
		field.status=field.status-0;
		field.timeout=field.timeout-0;
		const form = document.getElementById('gpress-form');
		$.ajax({
			url:form.action,
			type:form.method,
			contentType: "application/json;charset=utf-8",
			dataType:"json",
			data:JSON.stringify(field),
			error:function(){
				layer.msg("修改错误,请重试!");
			},
			success: function (result) {
					if (result.statusCode == 1) {
						layer.confirm('修改成功,是否继续修改?', {
							icon: 3,
							title: "确认",
							btn: ['返回列表', '继续修改'] //按钮
						}, function () {
							window.location.href = '{{basePath}}admin/{{.UrlPathParam}}/list';
						});
					} else {
						layer.msg("修改失败!");
					}
				}
		});
        return false; // 阻止默认 form 跳转
	  });
	});
	</script>
